<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目产品列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div>
     <div id="pageInTab" class="pageInTab">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox" style="display:none">
                <div class="label">产品名称</div>
                <div class="field">
                    <input name="prdNm" id="prdNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
           <div class="fieldBox" style="display:none">
                <div class="label">产品型号</div>
                <div class="field">
                    <input name="prdMdl" id="prdMdl" type="text" class="ui-textbox" value="">
                </div>
            </div>
               <div class="fieldBox" style="display:none">
                <div class="field" style="color: red">(说明：左侧查询条件用于查询已添加至下方产品列表中信息)</div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <!-- <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span> -->
               <sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjBscInfo" pInstId="${pInstId}">
	               <span id="searchBtn" class="sq-button sq-button-round">刷新</span>
	               <%--<span id="addBtn" onclick="addBtn();" class="sq-button sq-button-round">新增</span>--%>
	               <%--<span id="addBtn" onclick="test1();" class="sq-button sq-button-round">新增</span>--%>
	               <%--<span id="addGuaBtn" onclick="addGua();" class="sq-button sq-button-round">新增挂车</span>--%>
	               <span id="removeBtn" onclick="removeBtn();" class="sq-button sq-button-round"> 删除</span>
               </sys:FlowFrmAth>
            </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div>
	</div>
		</div>
			</div>
<script type="text/javascript">
	var grid = null;
	var prjId ='${prjId}';
	var detailFlag = '${detailFlag}';
	var changeFlag = '${changeFlag}';
	var prjTypCd = '${prjTypCd}';
	var insCode = '${insCode}';
	$(function () {
		//重卡工行卡贷 单独添加页面
		if(prjTypCd==ProjectConstant.CODE_PRJ_TYP_CD_DSFGHKDCPSZ){
			//屏蔽添加、删除按钮
			$("#removeBtn").hide();
			$("#addBtn").hide();
		}
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/project/prjprdbscinfo/initList.do?prjId='+prjId,
	    	method : 'get',
	        columns: [
	                  { display: '产品名称', name: 'prdNm', minWidth: 140 ,
	  	            	render: function (rowdata, rowindex, value, column) { 
	  	            		var h = '';
	  	            		    h+='<a class="sq-button-hasicon" href="javascript:detailBtn(';
	  	                        h+="'"+rowdata.id+"'";
	  	                        h+=')">'+value+'</a>'
	  	                        return h;
	  	            		},
	  	            	enabledSort:true},
	            { display: '车辆型号', name: 'prdMdl', minWidth: 140 , enabledSort:true},
	            { display: '产品数量', name: 'prdQty', minWidth: 50 , enabledSort:true},
	            { display: '产品品牌', name: 'brCd', width: 140 , enabledSort:true},
	            { display: '供应商名称', name: 'splNm', width: 140, 
	            	   render: function (rowdata, rowindex, value){
	                    	  var h="";
	                    	if(value&&rowdata.splInfoVO&&rowdata.splInfoVO.sysFlowSHDTOList){
	                    		var audStsCd = rowdata.splInfoVO.sysFlowSHDTOList[0].audStsCd;
	                      		if(rowdata.splInfoVO&&audStsCd){
	  	  	            		  if(audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
	  	  		                    	h+='<i class="ico_flasher"></i>';
	  	  		                    }
	  	  	            		}	                    		
		                     	h+='<a href="javascript:splDetail(';
		                        h+="'"+rowdata.splId+"'";
		                        h+=')">'+value+'</a>';
	                    	}else{
	                    	    if(value == null ) {
	                    	        value = "";
                                }
                                h+=value;
	                    	}
		                    return h;
		                },
	            	enabledSort:true},
	            { display: '厂商名称', name: 'mfrNm', minWidth: 200 , enabledSort:true},
	            { display: '收款人', name: 'splBankVO.rcptUnt', minWidth: 200 , 
	            	enabledSort:true},
	            { display: '收款账号', name: 'splBankVO.accNo', minWidth: 200 , 
	                 	 render: function (rowdata, rowindex, value){
	                      	  var h="";
	                      	if(value){
	                        		if(rowdata.splBankVO&&rowdata.splBankVO.audStsCd){
	    	  	            		  if(rowdata.splBankVO.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||rowdata.splBankVO.audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
	    	  		                    	h+='<i class="ico_flasher"></i>';
	    	  		                    }
	    	  	            		}	                    		
	   	                        h+=value;
	                      	}
	   	                    return h;
	   	                },
	            		enabledSort:true},
	            { display: '开户银行', name: 'splBankVO.bkNm', minWidth: 200 , enabledSort:true},
	            { display: '开户行号', name: 'splBankVO.bkNo', minWidth: 200 , enabledSort:true},
	            { display: '金额合计', name: 'prdAmt', minWidth: 200 , 
	          	  totalSummary:
                  {
                      render: function (rowdata, column, cell)
                      {
                    	  var    h="￥" + FormatMoney((parseFloat(rowdata.sum)).toFixed(2));
                          return '<div style="color:red">总合计金额（元）:' + h + '</div>';
                      },
                      align: 'left'
                  },
	            	enabledSort:true},
	             {
	                display: '操作',
	                isSort: false,
	                width: 100,
	                render: function (rowdata, rowindex, value){
	                	 var h= "";
	                	/*   if(rowdata.prjPrdDtlList.length>0){
	                        h='<a href="javascript:prjPrdPaySchDetail(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')"><i></i>查看支付表</a>';
	                        } */

	                 	<sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjBscInfo" pInstId="${pInstId}">
	                	  if(detailFlag!="true"&&rowdata.prdTypCd!=ProjectConstant.PRD_ZK_SZ_CD){
                              h+='<a href="javascript:modifyBtnTest(';
                              h+="'"+rowdata.id+"'";
                              h+=')"><i></i>修改</a>';
	                        // h+='<a href="javascript:modifyBtn(';
	                        // h+="'"+rowdata.id+"'";
	                        // h+=')"><i></i>修改</a>';
	                	  }else if(changeFlag=='0'){
	                		  h+='<a href="javascript:updateInfo(';
		                      h+="'"+rowdata.id+"'";
		                      h+=')"><i></i>修改供应商</a>';
	                	  }
	                  	 </sys:FlowFrmAth>
	                    return h;
	                }
	            } 
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        //isScroll: false,
	        checkbox:true,
	        rownumbers:true/* ,
	        onRenderComplete: function () {
	        	iframeResize ();
	        } */
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         data["prjId"] = prjId;
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	
	    $("#pageloading").hide();
	    if(detailFlag=="true"){
	    	$("#addBtn").hide();
	    	$("#removeBtn").hide();
	    	$("#addGuaBtn").hide();
	    	$("#splitPaySchBtn").hide();
	    	
	    }
	});
	
	function updateInfo(id){
		var callback = function(){
			 grid.reload();
		} 
        $.ligerDialog.open({  title: '供应商修改',height: 360,width: 1000, url:'<%=path%>/project/prjbscinfo/changePro.do?id='+id,callback:callback});
	}
	
	function splDetail(splId){
		//供应商详细信息
		var url  ="<%=path%>/product/splInfo/toDetailPage.do?id="+splId;
		Add_navTab('tab_spl_detail'+splId,'供应商详细信息',url);
	}
	function addBtn(){
		var callback = function(){
			 grid.reload();
		}
		//重卡工行卡贷 单独添加页面
		if(prjTypCd==ProjectConstant.CODE_PRJ_TYP_CD_DSFGHKDCPSZ){
			Add_navTab('tab_prj_prd_info_add','添加项目产品信息','<%=path%>/project/prjprdbscinfo/toPrjPrdGHAddPage.do?prjId='+prjId,callback);
		}else{
			$.ajax({
				type:'post',
				dataType:'text',
				data:{prjId:prjId},
				async:false,
				url:'<%=path%>/project/prjbscinfo/judgeThreshold.do',
				success:function(data){
					if(data=="failed"){
						top.$.ligerDialog.SQalert({content: "当前项目只允许添加一台车辆！",SQ_type: "error"});
					}else{
						$.ligerDialog.open({ title: '产品详细信息',height: 400,width: 800, url: '<%=path%>/project/prjbscinfo/toPrjPrdPage.do?id='+prjId, isResize: true ,callback:callback});
					}
				},
				error:function(data){
					
				}
			});
		}
	}

    /**
     * 新增挂车
     */
	function addGua(){
        var callback = function(){
            grid.reload();
        }

            $.ajax({
                type:'post',
                dataType:'text',
                data:{prjId:prjId},
                async:false,
                url:'<%=path%>/project/prjbscinfo/judgeThreshold.do',
                success:function(data){
                    if(data=="failed"){
                        top.$.ligerDialog.SQalert({content: "当前项目只允许添加一台车辆！",SQ_type: "error"});
                    }else{
                        $.ligerDialog.open({ title: '产品详细信息',height: 400,width: 800, url: '<%=path%>/vehicle/trailer/trailerList.do?prjId='+prjId, isResize: true ,callback:callback});
                    }
                },
                error:function(data){

                }
        })
    }
    function test1(){
        var callback = function(){
            grid.reload();
        }
        //重卡工行卡贷 单独添加页面
        if(prjTypCd==ProjectConstant.CODE_PRJ_TYP_CD_DSFGHKDCPSZ){
            Add_navTab('tab_prj_prd_info_add','添加项目产品信息','<%=path%>/project/prjprdbscinfo/toPrjPrdGHAddPage.do?prjId='+prjId,callback);
        }else{
            $.ajax({
                type:'post',
                dataType:'text',
                data:{prjId:prjId},
                async:false,
                url:'<%=path%>/project/prjbscinfo/judgeThreshold.do',
                success:function(data){
                    if(data=="failed"){
                        top.$.ligerDialog.SQalert({content: "当前项目只允许添加一台车辆！",SQ_type: "error"});
                    }else{
                        $.ligerDialog.open({ title: '产品详细信息',height: 400,width: 800, url: '<%=path%>/project/vehicle/vehicleList.do?prjId='+prjId, isResize: true ,callback:callback});
                    }
                },
                error:function(data){

                }
            });
        }
    }
	var callback = function(){
		 grid.reload();
	}
	function modifyBtn(id){
		var callback = function(){
			 grid.reload();
		}
		//重卡工行卡贷 单独添加页面
		if(prjTypCd==ProjectConstant.CODE_PRJ_TYP_CD_DSFGHKDCPSZ){
			Add_navTab('tab_prj_prd_info_add'+id,'修改项目产品信息','<%=path%>/project/prjprdbscinfo/toPrjPrdGHModifyPage.do?id='+id+'&&prjId='+prjId,callback);
		}else{
		Add_navTab('tab_prj_prd_info_modify'+id,'修改项目产品信息','<%=path%>/project/prjprdbscinfo/toModifyPage.do?id='+id+'&&prjId='+prjId,callback);
		}
		}
    function modifyBtnTest(id){
        var callback = function(){
            grid.reload();
        }
        //重卡工行卡贷 单独添加页面
        if(prjTypCd==ProjectConstant.CODE_PRJ_TYP_CD_DSFGHKDCPSZ){
            Add_navTab('tab_prj_prd_info_add'+id,'修改项目产品信息','<%=path%>/project/prjprdbscinfo/toPrjPrdGHModifyPage4Sys.do?id='+id+'&&prjId='+prjId,callback);
        }else{
            Add_navTab('tab_prj_prd_info_modify'+id,'修改项目产品信息','<%=path%>/project/vehicle/toModifyPage4Sys.do?id='+id+'&&prjId='+prjId,callback);
        }
    }
	function detailBtn(id){
		var callback = function(){
			 grid.reload();
		}
		var editFlag = true;
		//重卡工行卡贷 单独添加页面
		if(prjTypCd==ProjectConstant.CODE_PRJ_TYP_CD_DSFGHKDCPSZ){
			Add_navTab('tab_prj_prd_info_detail'+id,'项目产品详细信息','<%=path%>/project/prjprdbscinfo/toPrjPrdGHModifyPage.do?id='+id+'&&prjId='+prjId+'&&detailFlag='+editFlag,callback);
		}else{
		Add_navTab('tab_prj_prd_info_detail'+id,'项目产品详细信息','<%=path%>/project/vehicle/toModifyPage.do?id='+id+'&&prjId='+prjId+'&&detailFlag='+editFlag,callback);
		}
		}
	
	<%--  查看支付表信息
	function prjPrdPaySchDetail(prjPrdId){
		var prdFlag = true;
		Add_navTab('tab_prj_prd_info_modify','查看支付表','<%=path%>/project/prjprddtl/toListPage.do?prjPrdId='+prjPrdId+'&&prdFlag='+prdFlag);
	}  --%>

	//拆分支付表
	<%-- function splitPaySch(){
		var flag = false;
		//检查是否有项目报价方案
			$.ajax({
				type: 'get',
				dataType:'json',
				data:{prjId:prjId},
				url: '<%=path%>/project/prjquatprps/initList.do',
				success:function(msg){
					 if(msg.total >= 1){
							//拆分项目产品及项目支付表
							var selectedRows = grid.getSelectedRows();
							if(selectedRows.length <1){
								$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
								return;
							}
							var prdNm='';							
							var _ids = [];
							for ( var index in selectedRows) {
								//查找产品支付表是否存在
								$.ajax({
									type: 'get',
									async: false,
									dataType:'json',
									data:{prjId:prjId},
									url: '<%=path%>/project/prjprddtl/initList.do',
									success:function(msg){
											if(msg.rows){
												for(var i=0;i<msg.rows.length;i++){
													var obj = msg.rows[i];
													if(obj.paySchNo){
														flag = true;
														break;
													}
												}
											}
										}
									})
								_ids.push(selectedRows[index].id);
							}
							var params = {};
							params.prjPrdIdList=JSON.stringify(_ids);
							params.prjId=prjId;
							if(flag){
							$.ligerDialog.confirm("支付表已经存在，确定要重新拆分吗？", function (flag) {	
							if(flag == false)return;
							splitPrjPrdAndPaySch(params);
						});		
					}else{
						 splitPrjPrdAndPaySch(params);
					}
					 }else{
						 top.$.ligerDialog.SQalert({content: "请先配置项目报价方案！",SQ_type: "error"});
					 }
				}
			});

	} --%>
	function splitPrjPrdAndPaySch(params){
		var wait_dialog;
		$.ajax({
			type: 'post',
			dataType:'json',
			data:params,
			beforeSend: function(){
		          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		     },
			url: '<%=path%>	/project/prjprddtl/splitPrjPrdAndPaySch.do',
			success:function(msg){
				 if(msg.success == 1){
					 wait_dialog.close();
					 top.$.ligerDialog.SQalert({content: "拆分成功！",SQ_type: "success"});
				 }else{
					 wait_dialog.close();
					 top.$.ligerDialog.SQalert({content: "拆分失败！",SQ_type: "error"});
				 }
			}
		});
	}
	
	//删除所选商品信息
	function removeBtn(){
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length <1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		var _ids = [];
		for ( var index in selectedRows) {
			if(insCode==ProjectConstant.PRJ_INS_CODE_ICBC
					&&selectedRows[index].prdTypCd==ProjectConstant.PRD_ZK_SZ_CD
					&&selectedRows.length==1){
				 UIUtils.alertErrorHold1("不能单独删除上装产品！");
				 return false;
			}
			_ids.push(selectedRows[index].id);
		}
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			//查询是否有正式的报价方案，支付表信息，有提示删除后需重新报价，生成支付表信息
			var params = {};
			params.prjId=prjId;
			params.ids = JSON.stringify(_ids);
				$.ajax({
				type: 'get',
				dataType:'json',
				data:params,
				url: '<%=path%>/project/prjprdbscinfo/checkPrjPrdDtlExist.do',
				success:function(msg){
					 if(msg.data==true){
							$.ligerDialog.confirm("已经存在支付表信息，确定删除已经拆分的支付表信息吗？", function (flag) {	
								if(flag == false)return;
								//删除支付表信息，删除产品信息
								var params = {};
									params.ids = JSON.stringify(_ids);
									params.prjId = prjId;
								$.ajax({
									type: 'post',
									dataType:'json',
									data:params,
									url: '<%=path%>/project/prjprdbscinfo/removePrjPrdAndPrjPrdPayList.do',
									success:function(msg){
										 if(msg.success == 1){
											 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
											 grid.reload();
										 }else{
											 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
										 }
									}
								});
								
							});
					 }else{
						 //删除项目产品信息
							$.ajax({
								type: 'post',
								dataType:'json',
								data:{ids:JSON.stringify(_ids)},
								url: '<%=path%>/project/prjprdbscinfo/removeByIds.do',
								success:function(msg){
									 if(msg.success == 1){
										 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
										 grid.reload();
									 }else{
										 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
									 }
								}
							});
					 }
				}
			});
			
		});
	}
	function clearBtn(){
		var form = new liger.get("searchBar");
			form.setData({
			 prdNm:" ",
			 prdMdl:" "
		 });
	}
	//格式化为人民币格式
	function renderAmt(rowdata, rowindex, value) {
		if(typeof value =='number'){
        var h="￥" + FormatMoney((parseFloat(value)).toFixed(2));
        return h;
		}
    }
</script>

</body>
</html>